######################################################################
##  SOURCE FILE: Makefile                                           ##
##                                                                  ##
##     This is the make file for the C version of the ephemeris     ##
##     utilities. The user builds the software with the following   ##
##     pair of commands (choose either option 1a -or- 1b for first  ##
##     command):                                                    ##
##                                                                  ##
##     (1a) Enter "make 200" -- for working with DE200 data.        ##
##     (1b) Enter "make 405" -- for working with DE405 data.        ##
##     (2)  Enter "make all" -- to compile and link the programs.   ##
##                                                                  ##
######################################################################

#====================================================================#
#  Set Macro Values.                                                 #
#====================================================================#

Object_Files = convert.o        read_record.o      ephem_read.o      \
               ephem_util.o     extract.o          append.o          \
               print_header.o   scan_records.o

#====================================================================#
#  Define Targets & Dependencies.                                    #
#====================================================================#

all: ${Object_Files}
	gcc -o append append.o ephem_util.o -lm
	gcc -o convert convert.o ephem_util.o -lm
	gcc -o read_record read_record.o ephem_util.o -lm
	gcc -o extract extract.o ephem_util.o -lm
	gcc -o gdcon gdcon.c -lm
	gcc -o jdcon ephem_util.o jdcon.c -lm
	gcc -o print_header print_header.o ephem_util.o -lm
	gcc -o rdeph ephem_read.o rdeph.c -lm
	gcc -o scan_records scan_records.o ephem_util.o -lm

200: 
	cp ephem_types.h ephem_types.tmp
	rm ephem_types.h
	sed 's/EPHEMERIS .../EPHEMERIS 200/' ephem_types.tmp > ephem_types.h
	rm ephem_types.tmp

405: 
	cp ephem_types.h ephem_types.tmp
	rm ephem_types.h
	sed 's/EPHEMERIS .../EPHEMERIS 405/' ephem_types.tmp > ephem_types.h
	rm ephem_types.tmp

extract: extract.o ephem_util.o
	gcc -o extract extract.o ephem_util.o -lm

append: append.o ephem_util.o
	gcc -o append append.o ephem_util.o -lm

#====================================================================#
# Make dependencies on header files explicit.                        #
#====================================================================#

convert.o: ephem_util.h ephem_types.h
	gcc -c convert.c

read_record.o:  ephem_util.h ephem_types.h
	gcc -c read_record.c

ephem_util.o: ephem_types.h
	gcc -c ephem_util.c

ephem_read.o: ephem_types.h
	gcc -c ephem_read.c

extract.o: ephem_util.h ephem_types.h
	gcc -c extract.c

append.o: ephem_util.h ephem_types.h
	gcc -c append.c

print_header.o: ephem_util.h ephem_types.h
	gcc -c print_header.c

scan_records.o: ephem_read.h ephem_types.h
	gcc -c scan_records.c
